/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.uml_generator.manager.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.springframework.context.ApplicationContext;

import com.genia.toolbox.basics.exception.BundledException;
import com.genia.toolbox.basics.manager.StreamManager;
import com.genia.toolbox.spring.initializer.ApplicationContextHolder;
import com.genia.toolbox.uml_generator.manager.UmlGeneratorManager;

/**
 * Class to generate a xmi template to use for other projects
 */
public class XmiTemplateGenerator
{

  /**
   * the main method.
   * 
   * @param args
   *          the command line argument containing the name of the file to
   *          template and the name of the generated file
   * @throws BundledException
   *           when an error occurred
   * @throws IOException
   *           when an error occurred
   */
  public static void main(String[] args)
      throws BundledException, IOException
  {
    final ApplicationContext context = ApplicationContextHolder.getApplicationContext();
    final UmlGeneratorManager umlGeneratorManager = (UmlGeneratorManager) context.getBean("umlGeneratorManager");
    final StreamManager streamManager = (StreamManager) context.getBean("streamManager");
    File modeleFile = new File(args[0]);
    File returnFile = new File(args[1]).getCanonicalFile();
    returnFile.getParentFile().mkdirs();
    File result = umlGeneratorManager.generateTemplateFromModele(modeleFile);
    streamManager.copyStream(new FileInputStream(result), new FileOutputStream(returnFile));
    result.delete();
  }

}
